package com.xinjun.kingstar.ui.fragments.setting;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.hengjun.kingstar.sdk.base.fragment.BaseCompatFragment;
import com.xinjun.kingstar.R;
import com.xinjun.kingstar.ui.fragments.setting.child.SettingFragment;

/**
 * Created by SC-02 on 2018/9/19.
 * 这个是每个fragment中的根fragment 要继承BaseCompatFragment  即Activity内的第一个Fragment 或 Fragment内的第一个子Fragment
 * 在根fragment里面可以加载子fragment
 * Setting fragment
 */

public class SettingRootFragment extends BaseCompatFragment {

    /**
     * 实例化
     *
     * @return
     */
    public static SettingRootFragment newInstance() {
        Bundle bundle = new Bundle();
        SettingRootFragment settingRootFragment = new SettingRootFragment();
        settingRootFragment.setArguments(bundle);
        return settingRootFragment;
    }

    /**
     * 写布局
     *
     * @return 布局
     */
    @Override
    public int getLayoutId() {
        return R.layout.fragment_setting;
    }

    /**
     * 初始化这个布局的UI
     * @param view view
     * @param savedInstanceState savedInstanceState
     */
    @Override
    public void initUI(View view, @Nullable Bundle savedInstanceState) {

    }

    /**
     * 加载子布局
     * @param savedInstanceState savedInstanceState
     */
    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        if (savedInstanceState==null){
            loadRootFragment(R.id.fl_container, SettingFragment.newInstance());
        }else{//这里可能出现该fragment没被初始化的时候，就被强杀导致的没有load的子fragment
            if (findChildFragment(SettingFragment.class)==null){
                loadRootFragment(R.id.fl_container,SettingFragment.newInstance());
            }
        }
    }


}
